package cn.cs.service.impl;

import cn.cs.client.RestAppSettlementClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.AppSettlement;
import cn.cs.service.AppSettlementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class AppSettlementServiceImpl implements AppSettlementService {

    @Resource
    private RestAppSettlementClient appSettlementClient;

    public Map<String, String> getAppSettlementById(String id) throws Exception {
        return appSettlementClient.getAppSettlementById(id);
    }

    public List<AppSettlement> getAppSettlementListByMap(Map<String, Object> param) throws Exception {
        return appSettlementClient.getAppSettlementListByMap(param);
    }

    public Integer getAppSettlementCountByMap(Map<String, Object> param) throws Exception {
        return appSettlementClient.getAppSettlementCountByMap(param);
    }

    public Integer addAppSettlement(AppSettlement appSettlement) throws Exception {
        return appSettlementClient.addAppSettlement(appSettlement);
    }

    public Integer modifyAppSettlement(AppSettlement appSettlement) throws Exception {
        return appSettlementClient.modifyAppSettlement(appSettlement);
    }

    public Integer deleteAppSettlementById(String id) throws Exception {
        return appSettlementClient.deleteAppSettlementById(id);
    }

    public Page<AppSettlement> queryAppSettlementPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = appSettlementClient.getAppSettlementCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<AppSettlement> appSettlementList = appSettlementClient.getAppSettlementListByMap(param);
        page.setRows(appSettlementList);
        return page;
    }

}
